package mutithread;

/**
 * @author tongchen
 * @create 2023-01-03 20:20
 */
public class Exer03 {
    private static final long count = 10_0000_0000;
    public static void main(String[] args) {
        serial();
        concurrency();
    }
    public static void serial(){
        long begin = System.currentTimeMillis();
        //单线程
        int a=0;
        for(int i=0;i<count;++i){
            a--;
        }
        int b=0;
        for(int i=0;i<count;++i){
            b--;
        }
        long end=System.currentTimeMillis();
        System.out.println(end-begin);
    }
    public static void concurrency(){
        long begin=System.currentTimeMillis();
        Thread thread=new Thread(new Runnable() {
            @Override
            public void run() {
                int b=0;
                for(int i=0;i<count;++i){
                    b--;
                }
            }
        });
        int a=0;
        for(int i=0;i<count;++i){
            a--;
        }
        try {
            thread.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        long end=System.currentTimeMillis();
        System.out.println(end-begin);

    }
}

